package logic

import (
	"context"
	"shopping-cart/models/mysql"

	"shopping-cart/shoprpc/internal/svc"
	"shopping-cart/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type KuAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewKuAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *KuAddLogic {
	return &KuAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *KuAddLogic) KuAdd(in *shoprpc.KuAddRequest) (*shoprpc.KuAddResponse, error) {
	// todo: add your logic here and delete this line

	//var ku mysql.KuCun
	//mysql.DB.Debug().Where("id = ?", in.ShopId).Find(&ku)
	//if ku.ShopId == 0 {
	//	return nil, errors.New("商品不存在")
	//}

	ku := mysql.KuCun{
		ShopId: int(in.ShopId),
		KuNum:  int(in.KuNum),
	}
	mysql.DB.Debug().Create(&ku)

	return &shoprpc.KuAddResponse{
		KuCunId: int64(ku.ID),
	}, nil
}
